package com.taotao.search.service.ipml;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.taotao.common.pojo.Item;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.common.utils.ExceptionUtil;
import com.taotao.search.service.ISyncSolrService;

@Service
public class SyncSolrServiceIpml implements ISyncSolrService {
	@Value("${SOLR_BASE_URI}")
	private String SOLR_BASE_URI;

	@Autowired
	private SolrServer server;

	public TaotaoResult SyncSolrItemBaseInfo(Item item) {
		try {
			SolrInputDocument doc = new SolrInputDocument();
			doc.addField("id", item.getId());
			doc.addField("item_sell_point", item.getSell_point());
			doc.addField("item_price", item.getPrice());
			doc.addField("item_title", item.getTitle());
			doc.addField("item_image", item.getImage());
			doc.addField("item_category_name", item.getCategory_name());
			doc.addField("item_desc", item.getItem_desc());
			this.server.add(doc);
			this.server.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return TaotaoResult.build(500, ExceptionUtil.getStackTrace(e));
		}
		return TaotaoResult.ok();
	}

}
